package com.manager.modelserver.controller;


import com.alibaba.excel.EasyExcel;
import com.manager.modelserver.entry.BasBomList;
import com.manager.modelserver.entry.BomListData;
import com.manager.modelserver.service.IBasBomListService;
import com.manager.modelserver.service.listener.DemoDataListener;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 物料清单 前端控制器
 * </p>
 *
 * @author SedateC
 * @since 2021-09-26
 */
@RestController
@RequestMapping("/basbomlist")
public class BasBomListController {
    @Autowired
    IBasBomListService basBomListService;
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
    @RequestMapping("/getAll")
    public List<BasBomList> getAll(){
        List<BasBomList> list =  basBomListService.getBaseMapper().selectList(null);
        return list;
    }

    @PostMapping("/upload/excelBomList")
    public String saveExcelBomList(@RequestPart MultipartFile file) throws IOException {
        synchronized (BasBomListController.class){
            EasyExcel.read(file.getInputStream(), BomListData.class, new DemoDataListener(basBomListService,sqlSessionTemplate)).sheet().doRead();
        }
        return "success";
    }



}

